using UnityEngine;
using System.Collections;

public class DestroyingScript : MonoBehaviour 
{
	private float startingMoney = 10000f;
	private float currentMoney;
	public TextMesh moneyDisplay;
		
	// Use this for initialization
	void Start () 
	{
		this.currentMoney = this.startingMoney;
	}
	
	// Update is called once per frame
	void OnTriggerEnter (Collider element) 
	{
		float price = element.GetComponent<Product_Script>().GetPrice();
		
		element.GetComponent<Product_Script>().Kill();
		
		this.currentMoney -= price;
		
		if(this.currentMoney < 0)
		{
			Application.Quit();
		}
	}
	
	void OnGUI()
	{
		GUI.Box(new Rect(Screen.width * 0.85f, Screen.height * 0.85f, Screen.width * 0.1f, Screen.height * 0.05f), this.currentMoney.ToString());
	}
}
